$(document).ready(function(){
    
    var cookieName = 'accordionDroitsUtilisateur';
    
    var accordion = $( "#accordion" ).accordion({
        collapsible: true,
        autoHeight: false,
        active: ( $.cookies.get( cookieName ) || 0 ),
        change: function( e, ui )
        {
            $.cookies.set( cookieName, $( this ).find( 'h3' ).index ( ui.newHeader[0] ) );
        }
    });
    
    
    var listDroitsUtilisateurExistants = $('#listDroitsUtilisateurExistants').dataTable( {
        "bAutoWidth": false,
        "bJQueryUI": true,
        "bPaginate": true,
	"bSort": true,
        "bStateSave": false,
        "sPaginationType": "full_numbers",
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "droitsUtilisateur/listDroitsExistants",
        "oLanguage":
        {
            "sUrl": "datatable/language"
        },
        "aoColumnDefs": [ {"bSortable": false, "aTargets": [ 4 ]} ],
        "fnInitComplete": function(oSettings, json) {
            $('#listDroitsUtilisateurExistants_filter').find(":text").qtip({
                content: $('#listDroitsUtilisateurExistants_qtip'),
                position: {
                        my: 'bottom center', 
                        at: 'top center'
                },
                show: {
                    event: 'click',
                    effect: function() {
                        $(this).stop(0, 1).fadeIn(400);
                    }
                },
                hide: {
                    event: 'unfocus',
                    effect: function() {
                        $(this).stop(0, 1).fadeOut(400);
                    }
                },
                style: { 
                        tip: true,
                        classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded'
                }
            });  
        }
   });
   
   var listUser = $('#listUser').dataTable( {
        "bAutoWidth": false,
        "bJQueryUI": true,
        "bPaginate": true,
	"bSort": true,
        "bStateSave": false,
        "sPaginationType": "full_numbers",
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "droitsUtilisateur/listUtilisateur",
        "oLanguage":
        {
            "sUrl": "datatable/language"
        },
        "aoColumnDefs": [ {"bSortable": false, "aTargets": [ 7 ]} ],
        "fnInitComplete": function(oSettings, json) {
            $('#listUser_filter').find(":text").qtip({
                content: $('#listUser_qtip'),
                position: {
                        my: 'bottom center', 
                        at: 'top center'
                },
                show: {
                    event: 'click',
                    effect: function() {
                        $(this).stop(0, 1).fadeIn(400);
                    }
                },
                hide: {
                    event: 'unfocus',
                    effect: function() {
                        $(this).stop(0, 1).fadeOut(400);
                    }
                },
                style: { 
                        tip: true,
                        classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded'
                }
            });
            
            //refreshButtonsUser($('#listUser'));
        }
   });
   
   var listLot = $('#listLot').dataTable( {
        "bAutoWidth": false,
        "bJQueryUI": true,
        "bPaginate": true,
	"bSort": true,
        "bStateSave": false,
        "sPaginationType": "full_numbers",
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "droitsUtilisateur/listLot",
        "oLanguage":
        {
            "sUrl": "datatable/language"
        },
        "aoColumnDefs": [ {"bSortable": false, "aTargets": [ 4, 8 ]} ],
        "fnInitComplete": function(oSettings, json) {
            $('#listLot_filter').find(":text").qtip({
                content: $('#listLot_qtip'),
                position: {
                        my: 'bottom center', 
                        at: 'top center'
                },
                show: {
                    event: 'click',
                    effect: function() {
                        $(this).stop(0, 1).fadeIn(400);
                    }
                },
                hide: {
                    event: 'unfocus',
                    effect: function() {
                        $(this).stop(0, 1).fadeOut(400);
                    }
                },
                style: { 
                        tip: true,
                        classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded'
                }
            });
        }
        
   });
   
    $("#MAJDroits").click(function(){
        MAJDroits();
    });
    
});

function MAJDroits(){
    var noty_help = null;
    return $.ajax({
        type:'GET',
        url : "/user/MAJDroits",
        dataType: 'json',
        success: function(data){
            noty_help = myNoty(data.msg, data.status);
        },
        error: function(jqXHR, textStatus, errorThrown)
        {
            noty_help = myNoty("Erreur : "+errorThrown, "error");
        }
    });
}
